package view.login
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	
	import global.GameState;
	import global.Resource;
	
	import utils.EnterFrameTimer;
	import utils.TextTool;
	import utils.ColorTool;

	public class GameServerLogining extends Sprite
	{
		private var hintText:TextField;
		private var logo:DisplayObject;
		private var timer:EnterFrameTimer;
		private var index:int;
		
		public function GameServerLogining()
		{
			this.mouseChildren = false;
			this.mouseEnabled = false;
			initText();
			initTimer();
			initBg();
		}
		
		private function initBg():void
		{
			ColorTool.drawHallbg(this.graphics,GameState.GAME_WIDTH,GameState.GAME_HEIGHT);
		}
		
		private function initTimer():void
		{
			timer = new EnterFrameTimer(300);
			timer.addEventListener(TimerEvent.TIMER,onTimer);
		}
		
		private function onTimer(event:TimerEvent):void
		{
			index ++;
			if (index > 4)
			{
				index =0;
			}
			
			var addText:String  = "";
			for (var i:int=0; i<index; i++)
			{
				addText += ".";
			}
			
			hintText.text = "连接服务器中，请稍等" + addText; 
		}
		
		private function initText():void
		{
			hintText = TextTool.getTextField(200,20,14,0xFFFFFF,false,false,"center");
			
			hintText.text = "连接服务器中，请稍等...";
			addChild(hintText); 
		}
		
		public function setLogo():void
		{
			this.logo = Resource.logo;
			logo.x = (GameState.GAME_WIDTH - logo.width) * .5 + 10;
			logo.y = 150;
			addChild(logo);
			
			hintText.x = logo.x;
			hintText.y = logo.height + logo.y + 5;
			hintText.width = logo.width;
			
			timer.start();
		}
		
		public function clear():void
		{
			timer.stop();
		}
	}
}